package test.enba.i18n;

import com.enba.boot.i18n.I18nHelper;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/i18n")
public class HelloController {

  @Autowired private I18nHelper i18nHelper;

  @GetMapping
  public String hello() {
    Locale locale = LocaleContextHolder.getLocale();
    return i18nHelper.getMessage("hello.message", null, locale);
  }

  @GetMapping("/test-param")
  public String testParam() {
    Locale locale = LocaleContextHolder.getLocale();
    return i18nHelper.getMessage("test.param", "参数值", locale);
  }
}
